import Taro from '@tarojs/taro'
import {WX_CREATE_QRCODE, WX_LOGIN, WX_LOGOUT, WX_BINDPHONE, WX_USER} from '../constants/wx'

const INITIAL_STATE = {
  shareCodeImage: '',
  token: '',
  userInfo: {}
}
export default function wx(state = INITIAL_STATE, action) {
  switch (action.type) {
    case WX_CREATE_QRCODE: {
      return {...state, shareCodeImage: action.payload.url}
    }
    case WX_LOGIN: {
      return {...state, token: action.payload}
    }
    case WX_BINDPHONE: {
      return {...state, userInfo: action.payload}
    }
    case WX_LOGOUT: {
      return {...state, token: ''}
    }
    case WX_USER: {
      return {...state, userInfo: action.payload}
    }
    default:
      return state
  }
}
